package leetcode.l0601;

import leetcode.l0526.TreeNode;

/**
 * @author Retain
 * @date 2021/6/1 10:10
 */
public class Easy_合并二叉树_617 {

    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        if(root1 == null || root2 == null) {
            return root1 == null? root2 : root1;
        }
        // 合并根节点
        root1.val += root2.val;

        // 依次递归左树和右树，将所有对应节点的值都加到root1上。
        root1.left = mergeTrees(root1.left, root2.left);
        root1.right = mergeTrees(root1.right, root2.right);
        return root1;
    }


}
